package com.qiyun.erp.util.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.qiyun.erp.auth.emp.vo.EmpModel;

public class LoginInterceptor extends AbstractInterceptor {

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        String actionName = invocation.getProxy().getAction().getClass().getName();
        String methodName = invocation.getProxy().getMethod();
        String allName = actionName + "." + methodName;

        if ("cn.itcast.erp.auth.emp.web.EmpAction.login".equals(allName)) {
            return invocation.invoke();
        }

        //获取当前登录人信息
        EmpModel loginEm = (EmpModel) ActionContext.getContext().getSession().get(EmpModel.EMP_LOGIN_USER_OBJECT_NAME);
        //如果当前没有登录，跳转到登录页面
        if (loginEm == null) {
            //跳转到登录
            return "noLogin";
        }

        //执行原始操作
        return invocation.invoke();
    }
}
